package com.springcloudalibabaexample.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.springcloudalibabaexample.feign.NacosClientFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OpenFeignController {

    @Autowired
    private NacosClientFeignService nacosClientFeignService;

    @GetMapping("/index")
    @SentinelResource(value = "index",blockHandler = "indexBlockHandler",fallback = "indexFallback")
    public String index() {
        return nacosClientFeignService.index();
    }

    /**
     * 流控兜底方法
     * @param blockException
     * @return
     */
    public String indexBlockHandler(BlockException blockException){
        return "indexBlockHandler";
    }

    /**
     * 熔断兜底方法
     * @param throwable
     * @return
     */
    public String indexFallback(Throwable throwable){
        return "indexFallback";
    }
}